package org.budo.support.spring.web.client;

import org.budo.support.lang.util.StringUtil;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import lombok.extern.slf4j.Slf4j;

/**
 * @author lmw
 */
@Slf4j
public class BudoSpringRestTemplate extends RestTemplate {
    @Override
    public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) throws RestClientException {
        ResponseEntity<T> responseEntity = super.exchange(url, method, requestEntity, responseType, uriVariables);

        log.debug("#21 exchange, url=" + url + ", requestEntity=" + requestEntity + ", responseEntity=" + StringUtil.cutLeft(responseEntity + "", 100));
        return responseEntity;
    }

    @Override
    public <T> ResponseEntity<T> postForEntity(String url, Object request, Class<T> responseType, Object... uriVariables) throws RestClientException {
        ResponseEntity<T> responseEntity = super.postForEntity(url, request, responseType, uriVariables);

        log.debug("#29 exchange, url=" + url + ", request=" + request + ", responseEntity=" + StringUtil.cutLeft(responseEntity + "", 100));
        return responseEntity;
    }
}